package Model;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * Created by zl206 on 2016/11/6.
 */
public class Tool {
    public static String color(){
        return  "#"+get()+get()+get();
    }
    public static List<String> colors(int num){
        ArrayList<String> strings = new ArrayList<>();
        for (int i=0; i<num;++i){
            strings.add(color());
        }
        return strings;
    }
    private static String get(){
        return String.format("%02x",new Random().nextInt(0xA0));
    }
    public static boolean isClose(point p1,point p2,double l){
        if(getL(p1,p2)<l)return true;
        return false;
    }
    public static boolean isIn(point p1,point p2,double l1,double l2){
        double l=getL(p1,p2);
        if(l>l1&&l<l2)return true;
        return false;
    }
    public static double getL(point p1,point p2){
        double dx=p2.getX()-p1.getX();
        double dy=p2.getY()-p1.getY();
        return Math.sqrt(dx*dx+dy*dy);
    }
    public static point forward(point p1,double l,double r){
        point point=new point();
        point.setX(p1.getX()+l*Math.cos(r));
        point.setY(p1.getY()+l*Math.sin(r));
        return point;
    }

    public static point forward(point p1,point p2,double l){
        double dx=p2.getX()-p1.getX();
        double dy=p2.getY()-p1.getY();
        double v = Math.atan2(dy, dx);
        return forward(p1,l,v);
    }
    public static ConcurrentLinkedQueue<bgPoint> getBgPoints(int num,bg bg){
        ConcurrentLinkedQueue<bgPoint> points=new ConcurrentLinkedQueue<bgPoint>();
        for (int i = 0 ; i < num ; ++i){
            points.add(new bgPoint(bg));
        }
        return points;
    }
}
